﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace ProjectStore30032013.DAL
{
    class Controler
    {
        static string userLogin;
        
        public static string UserLogin
        {
            get { return Controler.userLogin; }
            set { Controler.userLogin = value; }
        }
        public static DateTime timeOfProgram()
        {
            return DateTime.Now;
        }
        public static bool testUser(string user, string pass)  //funtion test login of a user
        {
            try
            {
                DataCSQLDataContext v_dtct = new DataCSQLDataContext(new Controler().ConnectionString);
                Account v_ac = (from c in v_dtct.Accounts
                                where c.Id == user
                                select c).Single();
                if (pass == v_ac.Pass) return true;
                else return false;
            }
            catch (Exception v_e)
            {
                return false;
            }            
        }
        public  bool TestConnection () 
        {
            string sqlConnectionString = Properties.Settings.Default.VIBU_StoreConnectionString;
            SqlConnection connection = new SqlConnection();
            connection.ConnectionString = sqlConnectionString;
            try
            {
                connection.Open();
            }
            catch (Exception ex)
            {
                return false;
            }
            finally
            {
                connection.Close(); 
            }
            return true; 
        }
        public  bool TestConnection(string _serverName, string _userName, string _pass, string _databaseName)
        {
            string sqlConnectionString = @"Data Source=" + _serverName + ";Initial Catalog=" + _databaseName + ";User ID=" + _userName + ";Password=" + _pass + "";
            SqlConnection connection = new SqlConnection();
            connection.ConnectionString = sqlConnectionString;
            try
            {
                connection.Open();
            }
            catch (Exception ex)
            {
                return false;
            }
            finally
            {
                connection.Close();
            }
            return true; 
        }
        private string connectionString;

        public string ConnectionString
        {
            get { return Properties.Settings.Default.VIBU_StoreConnectionString; }
        }
    }
}
